package com.javabasic.algorithm.sangfor_interview;

import org.junit.Test;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2021/12/25 4:57 下午
 */
public class StrSeqToNumArray {

    /**
     * 题目一：
     * 1. 给定一个数字字符串序列，例如："1234567891012"
     * 2. 切割字符串且保证切割后的数据序列不变
     * 3. 要求切割的数据均满足在：[0,130]之间
     * 例如：
     * 1,23,45,6,78,9,1,0,12
     * 12,3,45,67,89,10,12
     * ......
     * 求满足条件的组合个数
     */
    @Test
    public void strSeqToNumArray() {
        String str = "1234567891012";
        int result = recursionGetResult(str);
        System.out.println(result);
    }

    private int recursionGetResult(String str) {
        int len = str.length();
        /**
         * 处理0-99的数据
         */
        if (len < 3) {
            return len;
        }
        int sum = 0;
        for (int i = len-1; i >= 0; i--) {
            if (inRangeOfCheck(str.substring(i,len))) {
                sum += recursionGetResult(str.substring(0,i));
            } else {
                break;
            }
        }
        return sum;
    }

    public boolean inRangeOfCheck(String str) {
        int len = str.length();
        if (len > 3) return false;
        Integer num = Integer.valueOf(str);
        return num >= 0 && num <= 130;
    }
}
